<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        canvas {
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
<canvas width="600" height="400"></canvas>

<script>
    var myCanvas = document.querySelector('canvas');
    var ctx = myCanvas.getContext('2d');
    /*画平行线*/
    ctx.beginPath();/*开启新路劲*/
    /*blue 10px*/
    ctx.moveTo(100,100);
    ctx.lineTo(300,100);
    /*设置颜色*/
    ctx.strokeStyle = 'blue';
    /*设置宽度*/
    ctx.lineWidth = 10;
    ctx.stroke();

    /*red 20px*/
    ctx.beginPath();/*开启新路劲*/
    ctx.moveTo(100,200);
    ctx.lineTo(300,200);
    ctx.strokeStyle = 'red';
    ctx.lineWidth = 20;
    ctx.stroke();

    /*green 30px*/
    ctx.beginPath();/*开启新路劲*/
    ctx.moveTo(100,300);
    ctx.lineTo(300,300);
    ctx.strokeStyle = 'green';
    ctx.lineWidth = 30;
    ctx.stroke();

    /*开启新的路径可以解决样式覆盖问题*/
</script>
</body>
</html>
